import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
//	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int testCases = Integer.parseInt(br.readLine().trim());
		int i = 1;
		while(testCases-- != 0) {
			String str = br.readLine();
			
			
			StringBuffer sb = new StringBuffer();
			int index = 0;
			while(str.charAt(index) != ' ') {
				sb.append(str.charAt(index++));
			}
			int m = Integer.parseInt(sb.toString());
			index++;
			
			sb = new StringBuffer();
			while(index < str.length() && str.charAt(index) != ' ') {
				sb.append(str.charAt(index++));
			}
			int n = Integer.parseInt(sb.toString());
			index++;
			
			sb = new StringBuffer();
			while(index < str.length()) {
				sb.append(str.charAt(index++));
			}
			
			String msg = sb.toString();
			System.out.println(i++ + " " + decodeMsg(m, n, msg));
		}
	}
	
//	public static void main(String[] args) throws Exception {
//		System.out.println(decodeMsg("10001"));
//	}
	
	
	private static String decodeMsg(int m, int n, String encodedMsg) {
		int[][] mat = new int[m][n];
		int index = 0;
		for(int i = 0; i < m; i++) {
			for(int j = 0; j < n; j++) {
				if(encodedMsg.charAt(index++) == '1') {
					mat[i][j] = 1; 
				}
			}
		}
		
		StringBuffer sb = new StringBuffer();
		
		StringBuffer current = new StringBuffer();
		int upperx = 0, uppery = 0;
		int lowerx = m - 1, lowery = n - 1;
		while(lowerx >= upperx && lowery >= uppery) {
			for(int j = uppery; j <= lowery; j++) {
				current.append(mat[upperx][j]);
				if(current.length() == 5) {
					sb.append(decodeMsg(current.toString()));
					current = new StringBuffer();
				}
			}
			
			for(int i = upperx + 1; i <= lowerx; i++) {
				current.append(mat[i][lowery]);
				if(current.length() == 5) {
					sb.append(decodeMsg(current.toString()));
					current = new StringBuffer();
				}
				
			}
			
			for(int j = lowery - 1; j >= uppery && lowerx > upperx; j--) {
				current.append(mat[lowerx][j]);
				if(current.length() == 5) {
					sb.append(decodeMsg(current.toString()));
					current = new StringBuffer();
				}
				
			}
			
			for(int i = lowerx - 1; i > upperx && lowery > uppery ; i--) {
				current.append(mat[i][uppery]);
				if(current.length() == 5) {
					sb.append(decodeMsg(current.toString()));
					current = new StringBuffer();
				}
			}
			
			upperx++;
			uppery++;
			lowerx--;
			lowery--;
		}
		
		return removeTralingZero(sb.toString());
	}
	
	private static String removeTralingZero(String str) {
		int index = str.length() - 1;
		while(index >= 0 && str.charAt(index) == ' ') {
			index--;
		}
		
		return str.substring(0, index + 1);
		
	}
	

	
	private static char decodeMsg(String encodedMsg) {
		int val = 0;
		for(int i = 0; i < encodedMsg.length(); i++) {
			if(encodedMsg.charAt(i) == '1') {
				val +=  Math.pow(2, (encodedMsg.length() - 1) -i);
			}
		}
		return getChar(val);
	}
	
	private static char getChar(int value) {
		if(value == 0) {
			return ' ';
		}
		
		return (char)('A'  + value - 1);
	}

}
